var mongoose = require('mongoose');

var db = {
    connect:function(address, options){
        options = options || {};
        mongoose.connect(address);
        var db = mongoose.connection;
        db.on('error', function(e){
            console.error.bind(console, 'connection error:'+e);
            options.error && options.error(e);
        });
        db.once('open', function() {
          // we're connected!
          console.log('db connected')
          options.open && options.open()
        });

    }
}

module.exports = db;
